package com.dj.kufangbiaoshi.controller;

import com.dj.kufangbiaoshi.model.AddBiaoShiVo;
import com.dj.kufangbiaoshi.model.QueryPageVo;
import com.dj.kufangbiaoshi.model.StatusModifyVo;
import com.dj.kufangbiaoshi.model.UpdateBiaoShiVo;
import com.dj.kufangbiaoshi.service.BiaoShiService;
import com.dj.kufangbiaoshi.util.BuildVo;
import com.dj.kufangbiaoshi.util.Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@CrossOrigin
@RequestMapping("warehouseTag")
public class BiaoShiController {
    @Autowired
    private BiaoShiService biaoShiService;
    @PostMapping(value = "/queryPage")
    public Vo queryPage(@RequestBody QueryPageVo queryPageVo){

        return biaoShiService.queryPage(queryPageVo);
    }

    @PostMapping("/updateStatus")
    public Vo modifyStatus(@RequestBody StatusModifyVo statusModifyVo){

        return biaoShiService.modifyStatus(statusModifyVo);
    }
    @PostMapping("/update")
    public Vo updateShuXing(@RequestBody @Valid UpdateBiaoShiVo updateShuXing, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return BuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return biaoShiService.updateShuXing(updateShuXing);
    }

    @PostMapping("/add")
    public Vo addShuXing(@RequestBody @Valid AddBiaoShiVo addBiaoShiVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return BuildVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return biaoShiService.addShuXing(addBiaoShiVo);
    }
}
